package com.cmw.auntapp.presenter;

import com.cmw.auntapp.constant.API;
import com.cmw.auntapp.constant.CommandType;
import com.cmw.auntapp.core.base.BasePresenter;
import com.cmw.auntapp.core.base.IBaseView;
import com.cmw.auntapp.core.util.SharedPreferencesUtil;
import com.cmw.auntapp.model.AuntModel;
import com.cmw.auntapp.model.OrderModel;

import java.util.HashMap;
import java.util.Map;

import static com.cmw.auntapp.constant.API.ORDER_INFO_GET;
import static com.cmw.auntapp.constant.API.ORDER_LIST_GET;
import static com.cmw.auntapp.constant.API.ORDER_SET_ARRIVE_TIME;
import static com.cmw.auntapp.constant.API.ORDER_SUM_GET;
import static com.cmw.auntapp.constant.API.ORDER_XSTATUS_UPDATE;
import static com.cmw.auntapp.constant.API.SMS_CODE_SEND;
import static com.cmw.auntapp.constant.Constant.SHOW_LOADING_KEY;
import static com.cmw.auntapp.constant.Constant.SHOW_LOADING_YES;
import static com.cmw.auntapp.constant.Constant.USER_MEMBERID_KEY;

/**
 * @desc: 订单 Presenter
 * @author: chengmingwei
 * @date: 2021/05/16 21:25 PM
 * @contact: phone(微信同号):13922111489 / email: 340360491@qq.com
 */
public class OrderPresenter extends BasePresenter<Map<String, String>> {
    private IBaseView iBaseView;

    private OrderModel orderModel;

    public OrderPresenter(IBaseView iBaseView) {
        this.iBaseView = iBaseView;
        init();
    }


    @Override
    protected String getTag() {
        return this.getClass().getSimpleName();
    }

    /**
     *  阿姨待抢订单
     */
    public void grabbing() {
        Map<String, String> params = new HashMap<>();
        params.put(SHOW_LOADING_KEY, SHOW_LOADING_YES);

        get(API.ORDER_GRABBING, CommandType.GRABBING, params);
    }

    /**
     * 获取阿姨应收/实收列表
     *
     * @param startDate 开始日期
     * @param endDate 结束日期
     */
    public void getSumAmount(String startDate, String endDate) {
        Map<String, String> params = new HashMap<>();
        params.put("requestSource", "1"); // 对象来源：1：阿姨，2：客户
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        postBody(ORDER_SUM_GET, params, CommandType.GET);
    }


    /**
     * 获取订单阿姨订单列表
     *
     * @param startDate 开始日期
     * @param endDate 结束日期
     */
    public void getList(String startDate, String endDate) {
        Map<String, String> params = new HashMap<>();
        params.put("requestSource", "1"); // 对象来源：1：阿姨，2：客户
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        postBody(ORDER_LIST_GET, params, CommandType.LIST);
    }


    /**
     * 获取订单详情
     * @param orderId
     */
    public void get(String orderId) {
        Map<String, String> params = new HashMap<>();
        params.put("id", orderId);
        get(API.parseAPI(ORDER_INFO_GET, params, "id"), CommandType.GET);
    }

    /**
     * 设置多少分钟达到
     * @param orderId
     */
    public void setArriveTime(String orderId, String minutes) {
        Map<String, String> params = new HashMap<>();
        params.put("id", orderId);
        params.put("minutes", minutes);
        get(API.parseAPI(ORDER_SET_ARRIVE_TIME, params, "id"), CommandType.SET_ARRIVETIME, params);
    }

    /**
     * 更新订单状态 [ 上钟，下钟]
     * @param orderId 订单ID
     * @param xstatus 订单状态 []
     *
     */
    public void updateXstatus(String orderId, String xstatus) {
        Map<String, String> params = new HashMap<>();
        params.put("id", orderId);
        params.put("xstatus", xstatus);
        put(API.parseAPI(ORDER_XSTATUS_UPDATE, params, "id", "xstatus"), params, CommandType.PUT);
    }

    /**
     * 取消订单
     * @param orderId 订单ID
     * @param cancelReason 取消原因
     *
     */
    public void cancel(String orderId, String cancelReason) {
        Map<String, String> params = new HashMap<>();
        params.put("id", orderId);
        params.put("objType", "2");
        params.put("cancelReason", cancelReason);
        postBody(API.ORDER_CANCEL, params, CommandType.SAVE);
    }


    @Override
    protected IBaseView getView() {
        return iBaseView;
    }


}
